/**
 * 
 */
package br.com.plurianual.model.dao.impl;

import javax.persistence.Query;

import br.com.plurianual.exception.DataAccessLayerException;
import br.com.plurianual.model.dao.MacroObjetivoDAO;
import br.com.plurianual.model.dao.OrgaoDAO;
import br.com.plurianual.model.entity.MacroObjetivo;
import br.com.plurianual.model.entity.Orgao;

/**
 * @author FRAGA
 *
 */
public class MacroObjetivoDAOImpl extends DAOImpl<MacroObjetivo, Integer> implements
		MacroObjetivoDAO {

	/*
	 * (non-Javadoc)
	 * 
	 * @see br.com.fraga.model.dao.impl.DAO#delete(T)
	 */
	@Override
	public final void deleteAndClearOrphans(MacroObjetivo macroObjetivo) throws DataAccessLayerException {
		try {
			log.debug("Delete object: " + getPersistentClass().getName());
			
			Query clearProgramaQuery = this.getEntityManager().createNamedQuery("deleteMacroObjetivo.clearPrograma");

			clearProgramaQuery.setParameter("macroObjetivo", macroObjetivo);
			
			clearProgramaQuery.executeUpdate();
			
			this.delete(macroObjetivo);
		} catch (Exception e) {
			handleException(e);
		}
	}

}
